
#ifndef	__KC_SAKCAB_AUCAB_HPP_2010__
#define	__KC_SAKCAB_AUCAB_HPP_2010__

#include <sys/types.h>
#include <vector>
#include <map>
#include <string>

#include <db_cxx.h>

#include "aubin.hpp"


namespace   sakcab   {

class   Aucab
{
    typedef int32_t   cid_type;

public  :
    Aucab( const char* ini_filename, const char* ini_section );
    ~Aucab();

public  :
    // insert record, or update it if the key exists
    int insert( cid_type   cid,
             const std::string& kpin,
             const std::string& key,
             const std::string& data );

    // insert record, or append it if the key exists
    int insertAppend( cid_type   cid,
             const std::string& kpin,
             const std::string& key,
             const std::string& data );

    // insert record, or ignore it if the key exists
    int insertIgnore( cid_type   cid,
             const std::string& kpin,
             const std::string& key,
             const std::string& data );

    int find( cid_type   cid,
             const std::string& kpin,
             const std::string& key,
                   std::string& data );

    int find( cid_type   cid,
             const std::string& kpin,
             const std::string& key,
                   std::vector< std::string >& data,
				   u_int32_t    limit = 0);

    int erase( cid_type cid,
               const std::string& kpin,
               const std::string& key );

public	:

    int insertAppend( cid_type   cid,
					  const std::vector< std::string >& kpin,
					  const std::vector< std::string >& key,
					  const std::vector< std::string >& data );

public	:

	int	slim( void );

private	:
	void	initialize( const char* ini_filename, const char* ini_section );
	void	finalize();


private :
    typedef Aubin*      aubin_ptr;
    typedef std::vector< aubin_ptr >   bins_type;
    typedef bins_type::iterator bins_iterator_type;

    aubin_ptr  _bin_default_p;
    bins_type  _bins;

    aubin_ptr   getBin( cid_type cid );


private	:
	std::string	_bin_default_settings;

	u_int32_t	_count_put_or_erase;
};  //// class Aucab


}   //// namespace sakcab


#endif	////	__KC_SAKCAB_AUCAB_HPP_2010__

